package com.billjc.hrm.action;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.struts2.ServletActionContext;

import com.billjc.hrm.base.IbatisSessionFactory;
import com.billjc.hrm.model.ItSkill;
import com.billjc.hrm.model.ParamArray;
import com.opensymphony.xwork2.ActionSupport;

public class ItSkillAction extends ActionSupport {
	private static final long serialVersionUID = -4813772412787388397L;
	private ItSkill itSkill = null;
	private String elementid = null;
	private String elementvalue = null;
	private ParamArray param = new ParamArray();
	private SqlSessionFactory sessionfactory = IbatisSessionFactory
			.getSqlSessionFactory();

	public String input() throws Exception {
		SqlSession session = sessionfactory.openSession();
		// it_skill中的id
		param.setId(Integer.valueOf(elementid
				.substring(elementid.indexOf("-") + 1)));
		System.out.println(elementid.substring(elementid.indexOf("-") + 1));
		// 字段名
		param.setParamName(elementid.substring(0, elementid.indexOf("-")));
		// 对应字段名的值
		param.setParamValue(elementvalue);
		session.update("itskill.employeeItSkillSingleInfo", param);
		session.commit();
		session.close();
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("UTF-8");
		PrintWriter out;
		out = response.getWriter();
		if ("" == elementvalue) {
			// 如果不用空格，则页面值为"click to edit"
			out.print(" ");
		} else {
			// 将页面传过来的值回传
			out.print(elementvalue);
		}
		return null;
	}

	public ItSkill getItskill() {
		return itSkill;
	}

	public void setItskill(ItSkill itskill) {
		this.itSkill = itskill;
	}

	public String getElementid() {
		return elementid;
	}

	public void setElementid(String elementid) {
		this.elementid = elementid;
	}

	public String getElementvalue() {
		return elementvalue;
	}

	public void setElementvalue(String elementvalue) {
		this.elementvalue = elementvalue;
	}

	public ParamArray getParam() {
		return param;
	}

	public void setParam(ParamArray param) {
		this.param = param;
	}

	public SqlSessionFactory getSessionfactory() {
		return sessionfactory;
	}

	public void setSessionfactory(SqlSessionFactory sessionfactory) {
		this.sessionfactory = sessionfactory;
	}

}
